package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeacherPlanApi;
import com.xuecheng.api.content.teacherplan.dto.TeachplanDTO;
import com.xuecheng.api.content.teacherplan.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachPlanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanController implements TeacherPlanApi {

    @Autowired
    private TeachplanService  teachplanService;

    @GetMapping("/teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTeacherPlanById(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO teachplanDTO = teachplanService.queryTeacherPlanById(courseBaseId, companyId);
        return teachplanDTO;
    }

    @PostMapping("/teachplan")
    public TeachplanDTO modifyOrCreateTeachPlan(@RequestBody TeachplanVO vo) {
        TeachplanDTO dto = TeachPlanConvert.INSTANCE.vo2dto(vo);
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO teachplanDTO = teachplanService.modifyOrCreateTeachPlan(dto, companyId);
        return teachplanDTO;
    }

    @DeleteMapping("/teachplan/{teachPlanId}")
    public void removeTeachPlan(@PathVariable Long teachPlanId) {
        Long companyId = SecurityUtil.getCompanyId();
        teachplanService.deleteTeachPlan(teachPlanId,companyId);


    }
}
